package vek.XML.Parsers;

import org.xml.sax.ContentHandler;
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import vek.XML.parsedObjects.ParsedMap;

/**
 * Parses the map XML file. This has the settings of the map.
 * @see XMLParserPOI
 * @author Christian, Michal og Jakob (Hold 1, gruppe 2)
 */
public class XMLParser_MapParser extends DefaultHandler implements ContentHandler {
    
    private String tempElementData;
    private ParsedMap parsedMap;
            
    private String location;
    private String backgroundFilename;
    private int widthOfBackground;
    private int heightOfBackground;

    @Override
    public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
        
    }

    @Override
    public void endElement(String uri, String localName, String qName) throws SAXException {
        if(localName.equals("location"))
        {
            location = tempElementData;
        }
        
        else if(localName.equals("backgroundFilename"))
        {
            backgroundFilename = tempElementData;
        }
        
        else if(localName.equals("widthOfBackground"))
        {
            widthOfBackground = Integer.valueOf( tempElementData );
        }
        
        else if(localName.equals("heightOfBackground"))
        {
            heightOfBackground  = Integer.valueOf( tempElementData );
        }
        else if(localName.equals("map"))
        {
            parsedMap = new ParsedMap(location, backgroundFilename, widthOfBackground, heightOfBackground);
        }
        
        
        
        
    }

    @Override
    public void characters(char[] ch, int start, int length) throws SAXException {
        
       tempElementData = new String(ch, start, length);
        
    }
    
    public ParsedMap getParsedMap()
    {
        return parsedMap;
    }
    
    

}
